<?php include "header.php"; ?>

<div class="container">
	<!------SEARCH-------->
	<div class="row">
		<div class="span7"></div>
		<div class="span3 offset2">
			<form class="form-search">
				<div class="input-append">
					<input type="text" class="span2 search-query">
					<button type="submit" class="btn">Search</button>
				</div>
			</form>
		</div>
	</div>
	<!------SEARCH EOF-------->

	<!------BODY-------->

	<div class="row">
		<div class="span8" id="content-wrapper">
			<div id="bbtvts_feed_list" class="span7">
				<?php 
				
					function ago($i){
					    $m = time()-substr($i,0,10); 
					    $o='just now';
					    $t = array('year'=>31556926,'month'=>2629744,'week'=>604800,'day'=>86400,'hour'=>3600,'minute'=>60,'second'=>1);
					    foreach($t as $u=>$s){
					        if($s<=$m){
								$v=floor($m/$s); 
								$o="$v $u".($v==1?'':'s').' ago'; 
								break;
							}
					    }
					    return $o;
					}
			
					session_start();
					$url = "http://localhost:8080/moms-diary/services/feeds/".$_SESSION['userid'];

					$auth = $_SESSION['username'].":".$_SESSION['password'];

					$context = stream_context_create(array(
					    'http' => array(
					        'header'  => "Authorization: Basic " . base64_encode($auth)
						)
					));
					$datas = file_get_contents($url, false, $context);
					$data = json_decode($datas,TRUE);
					
					//$json = file_get_contents('./test/ScrapBook_multi.json', FILE_USE_INCLUDE_PATH);
					//$data = json_decode($json, TRUE);
					//echo $json;
					//print_r($data);
					?>
					
					<?php foreach($data as $row):?>
					<div class="row">
						<div class="span2 bbtvts_feed_thumb">
							<ul class="the-icons">
<!-- 							<li><a href="#"><img class="icon-heart-empty" /></a></li>
							<li><a href="#"><img class="icon-random" /></a></li> -->
							</ul>
							<a href="#" class="thumbnail"> <img src="img.php?q=<?php echo $row["picPath"];?>"
								alt="">
							</a> <small><?php echo $row["title"];?></small>
							<div class="row">
								<a href="#" style="float: right;"> <span class="label label-info">Like</span>
									<span class="label label-success">Follow</span>
								</a>
							</div>
						</div>
						<div class="span5 bbtvts_feed_content">
							<div class="row">
								<div class="span7">
									<p>Comments</p>
								</div>
							</div>
							<?php foreach($row["comments"] as $comment):?>
								<div class="row comment_list">
									<div class="span5">
										<span class="username_list_body"><?php echo $comment["firstName"].".".$comment["lastName"];?>:</span> <span
											class="comments_list_body"><?php echo $comment["comment"];?></span>
									</div>
								</div>
								<div class="row ">
									<div class="span5 comment_list_border">
									<small><?php echo ago($comment["dateCreated"]);?></small></div>
								</div>
							<?php endforeach; ?>
							<div class="row ">
								<div class="span1">
									<textarea rows="3" cols="50"
										style="margin: 0px 0px 10px; height: 50px; width: 250px;"></textarea>
								</div>
							</div>
					</div>
					</div>
					<!-- FEED LIST EOF -->
					<hr>
					<?php endforeach; ?>
			</div>
		</div>
		<div class="span4">
		<?php include"sidebar.php"?>
		</div>
	</div>

	<!------BODY EOF-------->

</div>
<!-- /container -->
<hr>



<?php include "footer.php"; ?>
